package top.songxs.gmall.search.rpc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.search.biz.GoodsBizService;
import top.songxs.gmall.search.dto.SearchParamDTO;
import top.songxs.gmall.search.entity.Goods;
import top.songxs.gmall.search.vo.SearchResponseVo;

@RestController
@RequestMapping("api/inner/search")
public class GoodsRpcController {

    @Autowired
    private GoodsBizService goodsBizService;
    @PostMapping("saveGoods")
    public Result saveGoods(@RequestBody Goods goods){
        goodsBizService.saveGoods(goods);
        return Result.ok();
    }
    @GetMapping("deleteGoods/{skuId}")
    public Result deleteGoods(@PathVariable("skuId") Long skuId){
        goodsBizService.deleteGoods(skuId);
        return Result.ok();
    }


    @PostMapping(value = "/searchGoods")
    public Result<SearchResponseVo> search(@RequestBody SearchParamDTO searchParamDTO) {
        SearchResponseVo searchResponseVo = goodsBizService.searchGoods(searchParamDTO);
        return Result.ok(searchResponseVo);
    }

    @PutMapping("/updateHotScore")
    public Result updateHotScore(@RequestParam("goodsId") Long goodsId , @RequestParam("hotScore")Integer hotScore) {
        goodsBizService.updateHotScore(goodsId , hotScore) ;
        return Result.ok() ;
    }
}
